package com.bqy.myokgo;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.bqy.myokgo.base.MyBaseActivity;
import com.bqy.myokgo.base.okgo.OKHttp;
import com.bqy.myokgo.base.okgo.bean.GuestBean;
import com.bqy.myokgo.base.okgo.bean.XXResponse;
import com.bqy.myokgo.base.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.HashMap;
import java.util.Map;

import cn.thl.view.statemanager.StateListener;
import cn.thl.view.statemanager.StateManager;

public class HttpActivity extends MyBaseActivity {

    private StateManager mStateManager;
    private Map map = new HashMap();

    @Override
    public View setContentView() {
        return View.inflate(this, R.layout.activity_http, null);
    }

    @Override
    public void iniGreate(Bundle savedInstanceState) {
        super.iniGreate(savedInstanceState);
        mToolBar.setToolbarStr("十次十次");

        map.put("Token", "79a4ddc3ff957cb1f90dc5528f7be26d1.0.76Y87HH1M3JJQCWEA7QCP2FGW41D48922E12F339D56386C1D58D767E5C6A1217A");
        map.put("UserId", "31808291029285806");
        map.put("DepartDate", "2019-2-23");
        map.put("DepartCityCode", "CTU");
        map.put("ArriveCityCode", "PEK");
        map.put("FlightNo", "CA4111");
        map.put("CabinCode", "F");
        map.put("AirLineCode", "CA");
        map.put("CabinPrice", "1780");
        map.put("Discount", "30.5");


        Button button = findViewById(R.id.bbbbb);
        Button wwwwwwww = findViewById(R.id.wwwwwwww);
        Button tttttt = findViewById(R.id.tttttt);
        LinearLayout ssssss = findViewById(R.id.ssssss);
        setOnClick(button, wwwwwwww, tttttt);

        mStateManager = StateManager.builder(this)
                .setContent(ssssss)//为哪部分内容添加状态管理。这里可以是Activity，Fragment或任何View。
                .setErrorOnClickListener(new StateListener.OnClickListener() {
                    @Override
                    public void onClick(View view) {//添加异常状态时的点击事件。
                        mStateManager.showLoading();
                        Http();
                    }
                })
                .build();//构建
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.bbbbb:
                mStateManager.showLoading();
                Http();
                break;
            case R.id.wwwwwwww:
                PopupShow show1 = new PopupShow(HttpActivity.this);
                show1.showPopupWindow();
                break;
            case R.id.tttttt:
                PopupShowbuttom show2 = new PopupShowbuttom(HttpActivity.this);
                show2.showPopupWindow();
                break;
        }
    }

    private void Http() {
        OKHttp.post(map, "http://118.190.0.224:10006/api/FlightInfo/SearchGuestRule"
                , new StringCallback<XXResponse<GuestBean>>() {
                    @Override
                    public void onSuccess(Response response) {
                        mStateManager.showError();
                    }
                });
    }
}
